<!doctype html>
<html class="no-js">
<head>
    <meta charset="UTF-8">
    <title>修改密码 | 校园知事</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/x-icon" href="/favicon.ico">
    <link rel="stylesheet" href="/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/assets/css/admin.css">
    <link rel="stylesheet" href="/assets/css/appadmin.css">

</head>
<body>
      {{template "admin/naver.html" .}}
        <div class="admin-content">
            <div class="admin-content-body">
                <div class="am-cf am-padding am-padding-bottom-0">
                    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg" style=" background-color: #222222;">修改密码</strong> </div>
                </div>
                <hr />
                <div class="am-g">
                    <div class="am-u-sm-12 am-u-md-8">
                        <form class="am-form am-form-horizontal">
                        <input type="hidden" id="id" value="{{.Id}}">
                            <div class="am-form-group">
                                <label for="oldpwd" class="am-u-sm-3 am-form-label">原密码</label>
                                <div class="am-u-sm-9">
                                    <input type="password" id="oldpwd" maxlength="32" placeholder="请输入旧密码" value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label for="newpwd" class="am-u-sm-3 am-form-label">新密码</label>
                                <div class="am-u-sm-9">
                                    <input type="password" id="newpwd" maxlength="32" placeholder="请输入新密码" value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label for="rnewpwd" class="am-u-sm-3 am-form-label">确认新密码</label>
                                <div class="am-u-sm-9">
                                    <input type="password" id="rnewpwd" maxlength="32" placeholder="请再次输入新密码" value="">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3">
                                    <button type="button" class="am-btn am-btn-primary" onclick="changeUserPwd()">保存修改</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
      {{template "admin/footer.html" .}}
	<script src="/assets/js/jquery.md5.min.js"></script>
    <script type="text/javascript">
        function changeUserPwd() {
            var $id=$("#id");
            var $oldpwd=$("#oldpwd");
            if ($oldpwd.val().trim()==='') {
                layer.tips('请输入原来的密码', $oldpwd);
                $oldpwd.focus();
                return ;
            }
            var $newpwd=$("#newpwd");
			if ($newpwd.val().trim()==='') {
                    layer.tips('请输入新密码', $newpwd);
                    $newpwd.focus();
                    return ;
            }
			if ($newpwd.val().trim()===$oldpwd.val().trim()) {
                    layer.tips('新旧密码一样', $newpwd);
                    $newpwd.focus();
                    return ;
            }
            var $rnewpwd=$("#rnewpwd");
			if ($rnewpwd.val().trim()==='') {
                    layer.tips('请输入新密码', $rnewpwd);
                    $rnewpwd.focus();
                    return ;
            }
			if($rnewpwd.val().trim() != $newpwd.val().trim()){
				 layer.tips('两次输入的密码不一样', $newpwd);
                    $newpwd.focus();
                    return ;
			}
            $.lintul('/admin/user/cps',{id:$id.val().trim(),oldpwd:$.md5($oldpwd.val().trim()),newpwd:$.md5($newpwd.val().trim())},function(data){
                 if (data.status === 1) {
                        layer.msg('修改密码成功', { offset: '15%', icon: 6 ,time:1000}, function () {
                            window.location.href="/login";
                        });
                    } else {
                        layer.msg('修改密码失败,请检查后重试', { offset: '15%', icon: 5 });
                    }
            });
        }
    </script>
</body>
</html>
